﻿using Coldairarrow.Business.BackStage.ConsumeChats;
using Coldairarrow.Entity.BackStage.ConsumeChats;
using Coldairarrow.Util;
using Coldairarrow.Util.DTO;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.BackStage.ConsumeChats
{
    [Route("/BackStage/ConsumeChats/[controller]/[action]")]
    public class ChatBusinessController : BaseApiController
    {
        #region DI

        public ChatBusinessController(IChatBusinessBusiness chatBusinessBus)
        {
            _chatBusinessBus = chatBusinessBus;
        }

        IChatBusinessBusiness _chatBusinessBus { get; }

        #endregion

        #region 获取
        /// <summary>
        /// 后台——获取商家列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<ChatBusiness>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _chatBusinessBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 后台——获取商家详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ChatBusiness> GetTheData(IdInputDTO input)
        {
            return await _chatBusinessBus.GetTheDataAsync(input.Id);
        }

        /// <summary>
        /// 后台——获取商家下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SelectDTO>> GetBusnessList()
        {
            return await _chatBusinessBus.GetBusnessListAsync();
        }
        #endregion

        #region 提交

        /// <summary>
        /// 后台——保存/修改商家列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(ChatBusiness data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _chatBusinessBus.AddDataAsync(data);
            }
            else
            {
                await _chatBusinessBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _chatBusinessBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}